#ifndef PL_H
#define PL_H

#include <string.h>
#include "Def.h"
#include "Nodes.h"

class Pl{
		
	public:
				
		bool parse(string fileName){
			
			ifstream inp(fileName.c_str());
			if(!inp.is_open()){
				cerr<<"Can not open "<<fileName<<endl;
				exit(1);
			}
			
			char line[1024];
			char line2[1024];
			char name[256], type[256], direct[256], temp[256];
			Node *node;
			float x,y;
			NODE_ITERATOR it;
			int numArg;
			
			while(inp.good()){
				inp.getline(line, 1024);
				strcpy(line2,line);
				sscanf(line2, "%s\t%*s\n", temp); 
				 if(strlen(line) < 5 || temp[0] == '#' || strncmp(temp, "UCLA", 4) == 0)
            		continue;
            		
       			 numArg = sscanf(line, "%s%f%f\t:\t%s%s\n", name, &x, &y, direct, type);  
				//numArg=sscanf(line,"         %s         %d          %d    :  %s  %s",name,&x,&y,direct,type);
				node = new Node();
				node->name = name;
				it = nodes.nodes.find(node);
				if(it==nodes.nodes.end())
					it = nodes.terminals.find(node);
				if(it==nodes.terminals.end()){
					cerr<<"Not found Node"<<name<<endl;
					exit(1);
				}
				delete node;
				node = *it;
				node->ll_xcoord=x;
				node->ll_ycoord=y;
				if(numArg==5){
					if(!strcmp(type,"/FIXED"))
						node->pl_movetype = FIXED;
					else
						node->pl_movetype = FIXED_NI;
				}
			}	
			inp.close();
			return true;
		}
	};	
				
	extern Pl pl;
				
#endif

